﻿CREATE PROCEDURE [dbo].[proc_ContactPerson_GetItem_Main]
	(
		@CustomerId uniqueidentifier
	)
AS
	Select 
	Top 1
	Id,
	CustomerId,
	PersonId,
	ZName,
	Sex,
	[Position],
	OfficeTel,
	HomeTel,
	Mobile,
	Email,
	CreateDate,
	IsMain,
	PersonTypeId,
	(Select Title From Contact_Type Where Id=ContactPerson.PersonTypeId) As PersonType,
	Age,
	Weixin
	From ContactPerson 
--Where CustomerId=@CustomerId and IsMain=1
	Where CustomerId=@CustomerId And 
	((Mobile<>'' And (Mobile Is Not Null)) Or 
	(OfficeTel<>'' And (OfficeTel Is Not Null)) Or 
	(HomeTel<>'' And (HomeTel Is Not Null)))
	Order By IsMain Desc,PersonTypeId,CreateDate Desc
	RETURN

